﻿using System;
using System.Data;
using System.Data.OracleClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public partial class Show_MonthQoQ : BasicPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            AttributeBind();
            Report_Bind();
        }        
    }

    protected void Query_Click(object sender, EventArgs e)
    {
        Report_Bind();
    }

    protected void Excel_Click(object sender, EventArgs e)
    {
        DGToExcel(Report, DurationList);
    }

    private void AttributeBind()
    {
        Month_A.Text = DateTime.Now.ToString("yyyy年MM月");
        Month_A.Attributes.Add("onclick", "WdatePicker({el:$dp.$('EndDate'),dateFmt:'yyyy年MM月',maxDate:'%y年%M月',minDate:'2014年3月'});");
    }

    public override void VerifyRenderingInServerForm(Control control)
    {
        //base.VerifyRenderingInServerForm(control);
    }

    private void Report_Bind()
    {
        string sqlstr = "AB_GetReport_Pk.GetUNLinkBy";
        OracleParameter[] _params = {
                new OracleParameter("v_Month",OracleType.VarChar,6),
				new OracleParameter("V_Class",OracleType.VarChar,4),	
                new OracleParameter("v_County",OracleType.VarChar,6),	
				new OracleParameter("resultSet",OracleType.Cursor)
            };
        _params[0].Value = Month_A.Text.Replace("年", "").Replace("月","");
        _params[1].Value = CellClass_A.SelectedValue;
        string dep = GetDep();
        _params[2].Value = dep == "市分" ? "" : dep;
        _params[3].Direction = ParameterDirection.Output;
        DataSet ds = OracleHelper.ExecuteDataSet(sqlstr, CommandType.StoredProcedure, _params);
        Report.DataSource = ds;
        Report.DataBind();
        DurationList.DataSource = ds;
        DurationList.DataBind();
    }

    protected void Report_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            TableCellCollection tcHeader = e.Row.Cells;
            tcHeader.Clear();

            //第一行表头
            tcHeader.Add(new TableHeaderCell());
            tcHeader[0].Attributes.Add("rowspan", "2"); 
            tcHeader[0].Text = "县分";
            tcHeader.Add(new TableHeaderCell());
            tcHeader[1].Attributes.Add("rowspan", "2");
            tcHeader[1].Text = "基站数量";
            tcHeader.Add(new TableHeaderCell());
            tcHeader[2].Attributes.Add("colspan", "3");
            tcHeader[2].Text = "基站断站次数";
            tcHeader.Add(new TableHeaderCell());
            tcHeader[3].Attributes.Add("colspan", "4");
            tcHeader[3].Text = "基站断站率</th></tr><tr class='ui-widget-header'>";

            //第二行
            tcHeader.Add(new TableHeaderCell());
            tcHeader[4].Text = "上月";
            tcHeader.Add(new TableHeaderCell());
            tcHeader[5].Text = "当月";
            tcHeader.Add(new TableHeaderCell());
            tcHeader[6].Text = "变化";
            tcHeader.Add(new TableHeaderCell());
            tcHeader[7].Text = "上月";
            tcHeader.Add(new TableHeaderCell());
            tcHeader[8].Text = "当月";
            tcHeader.Add(new TableHeaderCell());
            tcHeader[9].Text = "变化";
            tcHeader.Add(new TableHeaderCell());
            tcHeader[10].Text = "环比";
        }
    }

    protected void DurationList_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            TableCellCollection tcHeader = e.Row.Cells;
            tcHeader.Clear();

            //第一行表头
            tcHeader.Add(new TableHeaderCell());
            tcHeader[0].Attributes.Add("rowspan", "2"); 
            tcHeader[0].Text = "县分";
            tcHeader.Add(new TableHeaderCell());
            tcHeader[1].Attributes.Add("rowspan", "2");
            tcHeader[1].Text = "基站数量";
            tcHeader.Add(new TableHeaderCell());
            tcHeader[2].Attributes.Add("colspan", "3");
            tcHeader[2].Text = "基站断站时长";
            tcHeader.Add(new TableHeaderCell());
            tcHeader[3].Attributes.Add("colspan", "4");
            tcHeader[3].Text = "基站平均断站时长</th></tr><tr class='ui-widget-header'>";

            //第二行
            tcHeader.Add(new TableHeaderCell());
            tcHeader[4].Text = "上月";
            tcHeader.Add(new TableHeaderCell());
            tcHeader[5].Text = "当月";
            tcHeader.Add(new TableHeaderCell());
            tcHeader[6].Text = "变化";
            tcHeader.Add(new TableHeaderCell());
            tcHeader[7].Text = "上月";
            tcHeader.Add(new TableHeaderCell());
            tcHeader[8].Text = "当月";
            tcHeader.Add(new TableHeaderCell());
            tcHeader[9].Text = "变化";
            tcHeader.Add(new TableHeaderCell());
            tcHeader[10].Text = "环比";
        }
    }
    protected void Report_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#D5E5EA'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
        }
    }
    protected void DurationList_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#D5E5EA'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
        }
    }
}
